<?php
namespace Users\Model;

use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGateway;
use Zend\Db\Sql;
use Zend\Db\Sql\Where;
use Zend\Db\Sql\Select;
use Zend\Paginator\Adapter\DbSelect;
use Zend\Paginator\Paginator;
use Zend\Db\Sql\Predicate;
use Zend\Db\Sql\Expression;

class AdminTable
{
    protected $tableGateway;
	protected $select;
	protected $resultSet;
	
	public function __construct(TableGateway $tableGateway)
    {
        $this->tableGateway = $tableGateway;
		$this->select = new Select();
    }
	public function getlogin($data)
	{	
	   $password=md5($data['adminPassword']);        
		$select = $this->tableGateway->getSql()->select()
			->where('super_admin="'.$data['adminUsername'].'"')
			->where('super_password="'.$password.'"');
		$resultSet = $this->tableGateway->selectWith($select);
		$row = $resultSet->current();
		return $row;
	}
	public function getpassword($pwd,$userid){ 
		$pwd=md5($pwd);
		$select = $this->tableGateway->getSql()->select();
		$select->where('password="'.$pwd.'"');
		$select->where('user_id="'.$userid.'"');
		$resultSet = $this->tableGateway->selectWith($select);
		$row = $resultSet->count();			
		return $row;
	}
	public function changepwd($pwd,$userid){
		$password=md5($pwd);
		$data = array(
				'user_id'       =>$userid,
				'password'      =>$password,
				);
		$changepassword=$this->tableGateway->update($data, array('user_id' => $data['user_id']));
		return 	$changepassword;			
	}
	public function checkadminLogin($admin)
    {		
		$password=md5($admin['adminPassword']);		
		$select = $this->tableGateway->getSql()->select()
				->where('email="'.$admin['adminUsername'].'"')
				->where('password="'.$password.'"');
		$resultSet = $this->tableGateway->selectWith($select);	
        $row = $resultSet->current();	
        return $row;
	}
}
	